import request from '@/utils/request'
import Qs from 'qs'

export function getServer(size, page, kw) {
    return request({
        url: '/server/?size=' + size + '&page=' + page + ((kw) && kw != '' ? '&kw=' + kw : ''),
        method: 'get'
    })
}

export function addServer(name, host, user, port) {
    return request({
        url: '/server/',
        method: 'post',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded, multipart/form-data' },
        transformRequest: [function(data) {
            data = Qs.stringify(data)
            return data
        }],
        data: {
            name: name,
            host: host,
            port: port,
            user: user
        }
    })
}

export function updateServer(id, name, host, user, port) {
    return request({
        url: '/server/' + id,
        method: 'put',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded, multipart/form-data' },
        transformRequest: [function(data) {
            data = Qs.stringify(data)
            return data
        }],
        data: {
            name: name,
            host: host,
            port: port,
            user: user
        }
    })
}

export function deleteServer(id) {
    return request({
        url: '/server/' + id,
        method: 'delete',
        headers: { 'Content-Type': 'application/json' }
    })
}